﻿#region references
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

/* Project dependencies */
using IcaGames.Objects;
using IcaGames.Logging;
using IcaGames.Database;
#endregion

namespace IcaGames.Database.ObjectManagement
{
    /*
     * Class that holds common methods used to manage Platform enumeration Objects.
     * 
     * @author
     * Rick Oonk
     * 
     * @version
     * 1.0
     * 
     * @update
     * 15-12-2009 by Rick Oonk.
     * Created Class and added attributes and standard functions. 
     */ 
    public static class PlatformManagement
    {
        public static bool GetPlatforms(List<Platform> platforms)
        {
            SqlCommand command = null;
            SqlDataReader dr = null;
            string commandText = "SELECT PLATFORM_ID FROM PLATFORM";

            try
            {
                command = Connection.GetCommand(commandText);
                command.CommandType = CommandType.Text;

                dr = Connection.GetSqlDataReader(command);
                while (dr.Read())
                {
                    Platform p = (Platform)Cast.CastToInteger(dr["PLATFORM_ID"]);
                    platforms.Add(p);
                }
            }
            catch (Exception ex)
            {
                Log.CreateLog("Exception while getting Platforms", "PLATFORMMANAGEMENT");
                Log.CreateLog(ex.Message, "PLATFORMMANAGEMENT");
                return false;
            }
            finally
            {
                Connection.CloseCommand(command, dr);
            }
            return true;
        }
    }
}
